<?php

use yii\db\Migration;

class m170930_012651_create_classroom_group extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }

    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%classroom_group}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'name' => $this->string(50)->defaultValue(null).' COMMENT \'组名\'',
                'type' => $this->smallInteger()->defaultValue(0).' COMMENT \'类型 0 同教室 1 多教室\'',
                'created_at' => $this->integer()->defaultValue(0) .' COMMENT \'添加时间\''
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v){
            $this->db = $v;
            $this->dropTable('{{%classroom_group}}');
        }
    }
}
